package com.yf.springboot.completablefuture;

import com.yf.springboot.util.FakeUtil;

import java.util.concurrent.CompletableFuture;

public class SupplyAsync {
    public static void main(String[] args) {
        FakeUtil.printTimeAndThread("小白进入餐厅");
        FakeUtil.printTimeAndThread("小白点了 蕃茄炒蛋 + 一碗米饭");

        CompletableFuture<String> cf1 = CompletableFuture.supplyAsync(() -> {
            FakeUtil.printTimeAndThread("厨师炒菜");
            FakeUtil.sleepMillis(300);
            FakeUtil.printTimeAndThread("厨师打饭");
            FakeUtil.sleepMillis(100);
            return "蕃茄炒蛋 + 米饭 做好了";
        });

        FakeUtil.printTimeAndThread("小白在打王者");
        FakeUtil.printTimeAndThread(String.format("%s, 小白开吃", cf1.join()));
    }
}
